package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import com.cykj.pos.domain.AizStatisticalMerchant;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.service.IAizStatisticalMerchantService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 代理渠道交易收益统计Controller
 *
 * @author xxl
 * @date 2025-03-21
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/statistical/statistical_merchant" )
public class AizStatisticalMerchantController extends BaseController {

    private final IAizStatisticalMerchantService iAizStatisticalMerchantService;

    /**
     * 查询代理渠道交易收益统计列表
     */
    @PreAuthorize("@ss.hasPermi('statistical:statistical_merchant:list')")
    @GetMapping("/list")
    public TableDataInfo list(AizStatisticalMerchant aizStatisticalMerchant) {
        startPage();
        List<AizStatisticalMerchant> list = iAizStatisticalMerchantService.queryList(aizStatisticalMerchant);
        return getDataTable(list);
    }

    /**
     * 导出代理渠道交易收益统计列表
     */
    @PreAuthorize("@ss.hasPermi('statistical:statistical_merchant:export')" )
    @Log(title = "代理渠道交易收益统计" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(AizStatisticalMerchant aizStatisticalMerchant) {
        List<AizStatisticalMerchant> list = iAizStatisticalMerchantService.queryList(aizStatisticalMerchant);
        ExcelUtil<AizStatisticalMerchant> util = new ExcelUtil<AizStatisticalMerchant>(AizStatisticalMerchant.class);
        return util.exportExcel(list, "statistical_merchant" );
    }

    /**
     * 获取代理渠道交易收益统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('statistical:statistical_merchant:query')" )
    @GetMapping(value = "/{userId}" )
    public AjaxResult getInfo(@PathVariable("userId" ) Long userId) {
        return AjaxResult.success(iAizStatisticalMerchantService.getById(userId));
    }

    /**
     * 新增代理渠道交易收益统计
     */
    @PreAuthorize("@ss.hasPermi('statistical:statistical_merchant:add')" )
    @Log(title = "代理渠道交易收益统计" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AizStatisticalMerchant aizStatisticalMerchant) {
        return toAjax(iAizStatisticalMerchantService.save(aizStatisticalMerchant) ? 1 : 0);
    }

    /**
     * 修改代理渠道交易收益统计
     */
    @PreAuthorize("@ss.hasPermi('statistical:statistical_merchant:edit')" )
    @Log(title = "代理渠道交易收益统计" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AizStatisticalMerchant aizStatisticalMerchant) {
        return toAjax(iAizStatisticalMerchantService.updateById(aizStatisticalMerchant) ? 1 : 0);
    }

    /**
     * 删除代理渠道交易收益统计
     */
    @PreAuthorize("@ss.hasPermi('statistical:statistical_merchant:remove')" )
    @Log(title = "代理渠道交易收益统计" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}" )
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(iAizStatisticalMerchantService.removeByIds(Arrays.asList(userIds)) ? 1 : 0);
    }
}
